//
//  TTMessage.swift
//  TTCoreData
//
//  Created by Toj on 3/30/21.
//

import Foundation

open class TTMessage: Object {
    public var text = ""
    
    private var vn_width: CGFloat = 0
    private var vn_height: CGFloat = 0
}

let lrMargin: CGFloat = 25
let maxWidth = 240 - lrMargin * 2
extension TTMessage {
    public var textWidth: CGFloat {
        if vn_width > 0 { return vn_width }
        
        let font = TTFont.systemFont(ofSize: 11)
        // +5 补误差
        var width = text.tt_stringWidth(font: font, maxHeight: 15) + 5
        if width > maxWidth { width = maxWidth }
        vn_width = width
        return vn_width
    }
    
    public var textHeight: CGFloat {
        if vn_height > 0 { return vn_height }
        
        let font = TTFont.systemFont(ofSize: 11)
        let height = text.tt_stringHeight(font: font, maxWidth: maxWidth)
        vn_height = height
        return vn_height
    }
}
